<?php
	include("../connect.php");
	
	$ms_mt_rv = $_REQUEST['mt_rv'];
	mysql_query("SET character_set_results=utf8");
	$rs=mysql_query("SELECT * 
					 FROM mau_tin_rv a, muc_tin b 
					 WHERE a.ms_muc_tin = b.ms_muc_tin AND a.ms_mau_tin_rv='$ms_mt_rv'");
	$rw=mysql_fetch_array($rs);
	$ms_muc_tin = $rw['2'];
	$tieu_de = $rw['3'];
	$noi_dung = $rw['4'];
	$noi_dang = $rw['6'];
	$hinh_minh_hoa = $rw['7'];
	$thoi_gian_song = $rw['8'];
	$vip = $rw['9'];
	$giay_phep = $rw['11'];
	$ms_loai_tin = $rw['13'];
?>
<div class="table"><h2><span>Cập Nhật Mẩu Tin Rao Vặt</span></h2></div><br />
<form action="thanh_vien/xl_sua_mau_tin_cn.php?ms_mt=<?php echo $ms_mt_rv ?>" method="post" name="sua_mt_rv" class="form" enctype="multipart/form-data" onsubmit="return validate(this)">
        <table width="100%" cellpadding="0" cellspacing="0">
        	<tr>
            	<td><label>Mã số mẩu tin</label></td>
                <td><input type="text" readonly="readonly" value="<?php echo $ms_mt_rv ?>" size="75" /></td>
            </tr>
        	<tr>
            <td><label>Loại tin</label></td>
            <td>
            	<input type="text" readonly="readonly" size="75" value="<?php if($vip == '1'){echo "VIP";} else echo "Thường";?>"></input>
                <input type="hidden" name="loai_tin" id="loai_tin" value="<?php echo $vip ?>"/>
            </td>
          </tr>
          <tr>
            <td><label for="txtnoi_dang">Nơi đăng(*)</label>
            </td>
            <td>
            <select name="txtnoi_dang" id="txtnoi_dang">
                <option value="">Chọn nơi đăng...</option>
                <?php
                    $arr = array("An Giang","Bến Tre","Bạc Liêu",
                                 "Cà Mau","Cần Thơ","Đồng Tháp",
                                 "Hậu Giang","Kiên Giang","Long An",
                                 "Sóc Trăng","Tiền Giang","Trà Vinh","Vĩnh Long");
                    $n = count($arr);
                    $i=0;
                    for($i=0;$i<$n;$i++){
                ?>
                  <option value="<?php echo $arr[$i];?>" <?php if($arr[$i]==$noi_dang){echo "selected='selected'";};?> ><?php echo $arr[$i];?></option>
                <?php
                    }
                ?>
            </select>
            </td>
          </tr>
			<?php
                $sql = "SELECT * FROM the_loai_tin";					
                $rs=mysql_query($sql);
            ?>
          <tr>
            <td><label for="ms_loai_tin">Chọn thể loại(*)</label>
            </td>
            <td>
            <select id="txtms_loai_tin" name="txtms_loai_tin" onchange="hienMuc_tin(this.value);">
                <option value="" select="selected">Chọn thể loại...</option>
                <?php
                while ($row=mysql_fetch_array($rs)){
                ?>
                <option value="<?php echo $row['0']; ?>" <?php if($row['0']==$ms_loai_tin){echo "selected='selected'";};?> > <?php echo $row['1']; ?></option>
                <?php	
                }
                ?>
            </select>
            </td>
          </tr>
          	<?php
                $sql = "SELECT * FROM muc_tin WHERE ms_loai_tin = $ms_loai_tin";					
                $rs=mysql_query($sql);
            ?>
          <tr>
            <td><label for="ms_muc_tin">Đăng vào mục tin(*)</label></td>
            <td id="muc_tin_col">
                <select id="txtms_muc_tin" name="txtms_muc_tin">
                    <option value="" select="selected">Chọn mục tin...</option>
                    <?php
					while ($row=mysql_fetch_array($rs)){
					?>
						<option value="<?php echo $row['0']; ?>" <?php if($row['0']==$ms_muc_tin){echo "selected='selected'";};?> > <?php echo $row['2']; ?></option>
					<?php	
					}
					?>
                </select>
            </td>
          </tr>
          <tr>
            <td><label for="tieu_de">Tiêu đề(*)</label>
            </td>
            <td><input id="txttieu_de" name="txttieu_de" type="text" size="75" value="<?php echo $tieu_de ?>"/></td>
          </tr>
          <tr><td/>&nbsp;</td><td>&nbsp;</td></tr>
          <tr>
            <td valign="top"><label for="noi_dung">Nội dung(*)</label>
            </td>
            <td><textarea id="txtnoi_dung" name="txtnoi_dung" rows="8" style="width:470px" ><?php echo $noi_dung ?></textarea></td>
          </tr>
          <tr>
          	<td>Hình minh họa</td>
          	<td><img src="uploads/<?php echo $hinh_minh_hoa ?>" width="110px" alt="No image" />
            	<input type="hidden" name="hinh_cu" id="hinh_cu" value="<?php echo $hinh_minh_hoa ?>" /></td>
          </tr>
          <tr>
            <td><label for="hinh_minh_hoa">Hình ảnh mới</label>
            </td>
            <td><input type="hidden" name="MAX_FILE_SIZE" value="300000">
            <input id="hinh_minh_hoa" name="hinh_minh_hoa" type="file"/></td>
          </tr>
          <?php
		  	if($vip == 1){
		  ?>
          <tr>
          	<td><label>Thời gian tồn tại(*)</label></td>
            <td>
            <select name="thoi_gian_song" id="thoi_gian_song">
                <option value="">Chọn thời gian tồn tại mẩu tin...</option>
                <option value="10" <?php if($thoi_gian_song==10){echo "selected='selected'";};?>>10 ngày</option>
                <option value="15" <?php if($thoi_gian_song==15){echo "selected='selected'";};?>>15 ngày</option>
                <option value="30" <?php if($thoi_gian_song==30){echo "selected='selected'";};?>>30 ngày</option>
            </select>
            </td>
          </tr>
          <?php
			}
		  ?>
          <tr>
 			<td></td>
    		<td>
        		<input type="submit" name="submit" id="submit" value=" Cập nhật " class="button"/>&nbsp;&nbsp;
   			</td>
  		  </tr>
        </table>
        </form>